
/*    This file is part of the Managarm operating system.
 *   Copyright (C) 2007, 2008, 2009  Alexander van der Grinten
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

package org.managarm.jmanavalib.core;

public final class VaClsInfo extends VaObject {
	public static int FLAG0_FINAL = 1;
	public static int FLAG0_STRUCT = 2;
	
	// identifier of the class
	public final String ident;
	
	// class version information
	public final int major;
	public final int minor;
	public final int revision;
	
	// flags of the class
	public final int flags0;

	public VaClsInfo(String ident, int major, int minor,
			int revision, int flags0) {
		this.ident = ident;
		this.flags0 = flags0;
		this.major = major;
		this.minor = minor;
		this.revision = revision;
	}

	// returns true if this class is compatible to "other"
	public boolean compatible(VaClsInfo other) {
		if(!ident.equals(other.ident))
			return false;
		if((flags0 & FLAG0_STRUCT) != (flags0 & FLAG0_STRUCT))
			return false;
		return true;
	}
	
	// builds a hash code based on fields
	// significant for compatibility
	public int compatibilityHash() {
		int hash = 17;
		hash = 37 * hash + ident.hashCode();
		hash = 37 * hash + ((flags0 & FLAG0_STRUCT) != 0 ? 0 : 1);
		return hash;
	}
	
	// see java.lang.Object
	@Override public boolean equals(Object other) {
		if(other instanceof VaClsInfo == false)
			return false;
		final VaClsInfo clsinfo = (VaClsInfo)other;
		if(!ident.equals(clsinfo.ident))
			return false;
		if(major != clsinfo.major)
			return false;
		if(minor != clsinfo.minor)
			return false;
		if(revision != clsinfo.revision)
			return false;
		if(flags0 != clsinfo.flags0)
			return false;
		return true;
	}
	
	// see java.lang.Object
	@Override public int hashCode() {
		int hash = 17;
		hash = 37 * hash + ident.hashCode();
		hash = 37 * hash + major;
		hash = 37 * hash + minor;
		hash = 37 * hash + revision;
		hash = 37 * hash + flags0;
		return hash;
	}
}
